package com.qqtech.qquan.mall.model;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.qqtech.core.common.util.StringUtil;
import com.qqtech.core.common.util.TimeUtil;
import com.qqtech.qquan.mall.enums.MallShopStatusDictEnum;
import com.qqtech.qquan.mall.enums.MallShopStyleDictEnum;
import com.qqtech.qquan.user.enums.UserConst;

@SuppressWarnings("serial")
public class MallShopVo extends MallShop{
	
    /** 所在省份名称 */
	private String provinceName;
    /** 所在城市名称 */
	private String cityName;
    /** 所在区、镇 名称*/
	private String regionName;
	/** 社区层级id */
	private Integer communityAddrId;
	/** 社区门牌号 */
	private String homeNum;
	/** 社区名称 */
	private String communityName;
	/** 创建人昵称 */
	private String userNick;
	/** 类目名称 */
	private String categoryName;
	/** 产品 */
	private List<MallProductVo> mallProductVoList;
	/** 是否在营业时间内 */
	private Boolean hasBus;
	/**收益总计：￥1116*/
	private BigDecimal totalIncome;
	/**待退款订单数量**/
	private Integer waitRefundCount;
	/**待发货订单数量**/
	private Integer waitSendCount;
	/**待收货订单数量**/
	private Integer waitReceiptCount;
	/** 是否收藏 */
	private Boolean hasCollect;
	/** 收藏数量 */
	private int collectCount;
	/** 备注（用于前台显示一些说明） */
	private String remarks1;
	/** 备注（用于前台显示一些说明） */
	private String remarks2;
	/**今日有效订单数量**/
	private Integer todayCompletedCount;
	
	/**今日有效订单总计：￥1116*/
	private BigDecimal totalTodayCompleted;
	/**
	 * 距离
	 */
	private BigDecimal distance;// 距离
	
	public String getCategoryName() {
		return categoryName;
	}
	public String getCityName() {
		return cityName;
	}
	public int getCollectCount() {
		return collectCount;
	}
	public Integer getCommunityAddrId() {
		return communityAddrId;
	}
	public String getCommunityName() {
		return communityName;
	}
	public String getFullLicensePic() {
		if (StringUtil.isBlank(super.getLicensePic())) {
			return "";
		}
		return super.getFileDomain() + "" + super.getLicensePic();
	}
	public String getFullLogo() {
		if (StringUtil.isBlank(super.getLogo())) {
			return "";
		}
		return super.getImgHandleDomain() + "" + super.getLogo() + UserConst.IMG_POSTFIX;
	}
	public Boolean getHasBus() {
		hasBus = false;
		if (super.getStatus() != null && super.getStatus().intValue() == MallShopStatusDictEnum.NORMAL.getCode()) {
			if (super.getBusStart() != null && super.getBusEnd() != null) {
				Calendar calendar = Calendar.getInstance();
				int nowHour = calendar.get(Calendar.HOUR_OF_DAY);
				int nowMinute = calendar.get(Calendar.MINUTE); 
				
				String[] bs = super.getBusStart().split(":");
				String[] be = super.getBusEnd().split(":");
				int bsHour = Integer.valueOf(bs[0]);
				int bsMin = Integer.valueOf(bs[1]);
				int beHour = Integer.valueOf(be[0]);
				int beMin = Integer.valueOf(be[1]);
				if (nowHour == bsHour && nowHour != beHour) {
					if (nowMinute >= bsMin) {
						hasBus = true;
					}
				} else if (nowHour == beHour && nowHour != bsHour) {
					if (nowMinute <= beMin) {
						hasBus = true;
					}
				}
				if (bsHour < beHour) { //比如 8：00到22：00
					if (nowHour > bsHour && nowHour < beHour) {
						hasBus = true;
					}
				} else if (bsHour > beHour) { //比如22：00到凌晨2：00
					if (nowHour > bsHour && nowHour <= 23) {
						hasBus = true;
					}
					if (nowHour >= 0 && nowHour < beHour) {
						hasBus = true;
					}
				} else {
					if (bsMin < beMin) { //比如08：00到08：30
						if (nowHour == bsHour) {
							if (nowMinute > bsMin && nowMinute < beMin) {
								hasBus = true;
							}
						}
					}
				}
			}
		}
		return hasBus;
	}
	
	public Boolean getHasCollect() {
		return hasCollect;
	}
	
	public String getHomeNum() {
		return homeNum;
	}
	
	public List<MallProductVo> getMallProductVoList() {
		return mallProductVoList;
	}
	
	/** 支持的支付方式:1-货到付款,2-在线支付,多个以;分开 */
	public String getPayTypeStr() {
		String payTypeStr = "";
		if (!StringUtil.isBlank(super.getPayType())) {
			String[] temp = super.getPayType().split(";");
			for (String t : temp) {
				if (!payTypeStr.equals("")) {
					payTypeStr += "，";
				}
				if (t.equals("1")) {
					payTypeStr += "线下";
				} else {
					payTypeStr += "线上";
				}
			}
		}
		return payTypeStr;
	}

	public String getProvinceName() {
		return provinceName;
	}

	public String getRegionName() {
		return regionName;
	}

	public String getRemarks1() {
		return remarks1;
	}

	public String getRemarks2() {
		return remarks2;
	}

	/** 配送类型:1-可自提,2-商家配送,3-圈圈配送,多个以;分开 */
	public String getSendDeliveryTypeStr() {
		String sendDeliveryTypeStr = "";
		if (!StringUtil.isBlank(super.getSendDeliveryType())) {
			String[] temp = super.getSendDeliveryType().split(";");
			for (String t : temp) {
				if (!sendDeliveryTypeStr.equals("")) {
					sendDeliveryTypeStr += "，";
				}
				if (t.equals("1")) {
					sendDeliveryTypeStr += "自提";
				} else if (t.equals("2")){
					sendDeliveryTypeStr += "商家配送";
				} else {
					sendDeliveryTypeStr += "圈圈配送";
				}
			}
		}
		return sendDeliveryTypeStr;
	}

	/** 配送类型:1-可自提,2-可配送,多个以;分开 */
	public String getSendDeliveryTypeStr2() {
		String sendDeliveryTypeStr = "";
		if (!StringUtil.isBlank(super.getSendDeliveryType())) {
			String[] temp = super.getSendDeliveryType().split(";");
			for (String t : temp) {
				if (t.equals("1")) {
					sendDeliveryTypeStr += "可自提，";
				} else if (sendDeliveryTypeStr.indexOf("可配送") == -1){
					sendDeliveryTypeStr += "可配送，";
				}
			}
		}
		if (!sendDeliveryTypeStr.equals("")) {
			sendDeliveryTypeStr = sendDeliveryTypeStr.substring(0, sendDeliveryTypeStr.length()-1);
		}
		return sendDeliveryTypeStr;
	}

	public String getStrAuditAt() {
		return TimeUtil.getStringTimeByFormat(getAuditAt(), "yyyy-MM-dd HH:mm");
	}
	
	public String getStrStyle() {
		String strStyle = "";
		if (super.getStyle() != null) {
			if (super.getStyle().intValue() == MallShopStyleDictEnum.LOCAL.getCode()) {
				strStyle = "社区店铺";
			} else if (super.getStyle().intValue() == MallShopStyleDictEnum.VIRTUAL.getCode()) {
				strStyle = "邻里店";
			} else if (super.getStyle().intValue() == MallShopStyleDictEnum.QQSTORE.getCode()) {
				strStyle = "圈圈便利店";
			}
		}
		return strStyle;
	}

	public Integer getTodayCompletedCount() {
		return todayCompletedCount;
	}

	public BigDecimal getTotalIncome() {
		return totalIncome;
	}
	public BigDecimal getTotalTodayCompleted() {
		return totalTodayCompleted;
	}
	public String getUserNick() {
		return userNick;
	}
	public Integer getWaitReceiptCount() {
		return waitReceiptCount;
	}
	
	public Integer getWaitRefundCount() {
		return waitRefundCount;
	}
	public Integer getWaitSendCount() {
		return waitSendCount;
	}
	
	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}
	
	public void setCollectCount(int collectCount) {
		this.collectCount = collectCount;
	}
	public void setCommunityAddrId(Integer communityAddrId) {
		this.communityAddrId = communityAddrId;
	}
	
	public void setCommunityName(String communityName) {
		this.communityName = communityName;
	}
	public void setHasBus(Boolean hasBus) {
		this.hasBus = hasBus;
	}
	
	public void setHasCollect(Boolean hasCollect) {
		this.hasCollect = hasCollect;
	}
	public void setHomeNum(String homeNum) {
		this.homeNum = homeNum;
	}
	public void setMallProductVoList(List<MallProductVo> mallProductVoList) {
		this.mallProductVoList = mallProductVoList;
	}
	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}
	public void setRegionName(String regionName) {
		this.regionName = regionName;
	}
	public void setRemarks1(String remarks1) {
		this.remarks1 = remarks1;
	}
	public void setRemarks2(String remarks2) {
		this.remarks2 = remarks2;
	}
	public void setTodayCompletedCount(Integer todayCompletedCount) {
		this.todayCompletedCount = todayCompletedCount;
	}
	public void setTotalIncome(BigDecimal totalIncome) {
		this.totalIncome = totalIncome;
	}
	public void setTotalTodayCompleted(BigDecimal totalTodayCompleted) {
		this.totalTodayCompleted = totalTodayCompleted;
	}
	public void setUserNick(String userNick) {
		this.userNick = userNick;
	}
	public void setWaitReceiptCount(Integer waitReceiptCount) {
		this.waitReceiptCount = waitReceiptCount;
	}
	public void setWaitRefundCount(Integer waitRefundCount) {
		this.waitRefundCount = waitRefundCount;
	}
	public void setWaitSendCount(Integer waitSendCount) {
		this.waitSendCount = waitSendCount;
	}
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}
	public BigDecimal getDistance() {
		return distance;
	}
	public Integer getIntDistance() {
		if (null != distance) {
			return distance.intValue();
		}
		return 0;
	}
	public String getCnDistance() {
		if (null != distance) {
			if(distance.intValue()>1000){
				return  distance.divide(new BigDecimal("1000"),1,BigDecimal.ROUND_HALF_DOWN)+" 公里";
			}else{
				return  distance.intValue()+" 米";
			}
		}
		return "";
	}
	public void setDistance(BigDecimal distance) {
		this.distance = distance;
	}
	
}